{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# HTTP 模块\n",
    "概述：HTTP模块，用于创建web服务器，接收用户请求与响应"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-11-07T04:00:38.350706Z",
     "start_time": "2020-11-07T04:00:38.261Z"
    }
   },
   "outputs": [],
   "source": [
    "//加载http模块\n",
    "var http = require('http');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-11-07T04:00:40.720653Z",
     "start_time": "2020-11-07T04:00:40.636Z"
    }
   },
   "outputs": [],
   "source": [
    "//创建web服务器\n",
    "var server = http.createServer((req, res)=>{\n",
    "    res.writeHead(200,{'content-type':'text/html'});\n",
    "    res.write('Hello');\n",
    "    res.end();\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-11-07T04:00:42.548850Z",
     "start_time": "2020-11-07T04:00:42.460Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<ref *1> Server {\n",
       "  maxHeaderSize: undefined,\n",
       "  insecureHTTPParser: undefined,\n",
       "  _events: [Object: null prototype] {\n",
       "    request: [Function (anonymous)],\n",
       "    connection: [Function: connectionListener],\n",
       "    listening: [Function: bound onceWrapper] { listener: [Function (anonymous)] }\n",
       "  },\n",
       "  _eventsCount: 3,\n",
       "  _maxListeners: undefined,\n",
       "  _connections: 0,\n",
       "  _handle: TCP {\n",
       "    reading: false,\n",
       "    onconnection: [Function: onconnection],\n",
       "    [Symbol(owner)]: [Circular *1]\n",
       "  },\n",
       "  _usingWorkers: false,\n",
       "  _workers: [],\n",
       "  _unref: false,\n",
       "  allowHalfOpen: true,\n",
       "  pauseOnConnect: false,\n",
       "  httpAllowHalfOpen: false,\n",
       "  timeout: 0,\n",
       "  keepAliveTimeout: 5000,\n",
       "  maxHeadersCount: null,\n",
       "  headersTimeout: 60000,\n",
       "  _connectionKey: '6::::8080',\n",
       "  [Symbol(IncomingMessage)]: [Function: IncomingMessage],\n",
       "  [Symbol(ServerResponse)]: [Function: ServerResponse],\n",
       "  [Symbol(kCapture)]: false,\n",
       "  [Symbol(asyncId)]: 18\n",
       "}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "服务器已经在localhost:8080位置运行了...\n"
     ]
    }
   ],
   "source": [
    "server.listen('8080',()=>{\n",
    "    console.log('服务器已经在localhost:8080位置运行了...');\n",
    "});"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Javascript (Node.js)",
   "language": "javascript",
   "name": "javascript"
  },
  "language_info": {
   "file_extension": ".js",
   "mimetype": "application/javascript",
   "name": "javascript",
   "version": "13.13.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
